import { defineStore, storeToRefs } from 'pinia'
import { getInfo } from '@/services/manager'

export const storeData = defineStore("dataStore",{
  // 数据 长久保存与localStorage
  persist: {
    enabled: true,
    strategies: [
      {
        storage: localStorage,
        paths: ['userinfo'],    //指定要长久化的字段
      }
    ]
  },
  state: () =>{
    return{
      xiaohu:'xiaohu',
      num: 1,
      userinfo: {}, // 用户的信息
      asideWidth: '250px',
      menus: [],
      ruleNames: []
    }
  },
  actions:{
    // 记录用户信息
    setUserinfo( user:Object ){
      this.userinfo = user
    },
    // 清除用户信息
    delUserinfo(){
      this.userinfo = {}
    },

    // 获取当前登录的用户信息
    // getInfo({ commit }){
    //   return new Promise((resolve, reject) =>{
    //     getInfo().then(res =>{
    //       // 存储 user 的信息
    //       this.setUserinfo(res.data.data)
    //       resolve(res)
    //     }).catch(err => reject(err))
    //   })
    // }

    handleAsideWidth(){
      this.asideWidth = this.asideWidth == '250px' ? '64px' : '250px'
      // console.log(this.asideWidth)
    },
    setMenus(menus:[]){
      this.menus = menus
    },
    setRuleNames(ruleNames:[]){
      this.ruleNames = ruleNames
    }
   
  },
  getters:{

  }

})